<template>
  <el-card style="max-width: 1500px">
    <template #header>
      <div class="card-header">
        <div class="card-nav">
          <span>Card Name</span>
          <div>
            <el-button @click="todos.handleAdd()">新增</el-button>
            <el-button @click="todos.filter = 'all'">全部</el-button>
            <el-button @click="todos.filter = 'unFinished'">未完成</el-button>
            <el-button @click="todos.filter = 'isFinished'">已完成</el-button>
          </div>
        </div>
      </div>
    </template>
    <el-table :data="filterTodos" style="width: 100%">
      <el-table-column prop="id" label="#" width="180" />
      <el-table-column prop="text" label="工作内容" width="180" />
      <el-table-column prop="isFinished" label="完成度" />
      <el-table-column label="Operations">
        <template #default="scope">
          <el-button size="small" @click="todos.handleFinish(scope.$index, scope.row)">
            完成
          </el-button>
          <el-button size="small" @click="todos.handleEdit(scope.$index, scope.row)">
            Edit
          </el-button>
          <el-button
            size="small"
            type="danger"
            @click="todos.handleDelete(scope.$index, scope.row)"
          >
            Delete
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <template #footer>Footer content</template>
  </el-card>
</template>

<script setup>
import { useTodos } from '@/stores/todo.js'
import { storeToRefs } from 'pinia'
const todos = useTodos()
const { filterTodos } = storeToRefs(todos)
</script>

<style lang="scss" scoped>
.el-card {
  width: 780px;
  .card-header {
    .card-nav {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
  }
}
</style>
